package com.softer.wxzj.common.util;

import com.softer.wxzj.entity.SysOperator;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 * ShiroUser class
 *
 * @author zcz
 * @desc shiro中用户主体信息
 * @date 2019/1/16
 */
public class ShiroUserUtil {
    /**
     * 获取用户主体
     *
     * @return
     */
    public static SysOperator getUser() {
        return (SysOperator) getSubject().getPrincipal();
    }

    /**
     * 获取用户名
     *
     * @return
     */
    public static String getUserName() {
        SysOperator u = (SysOperator) getSubject().getPrincipal();
        if (null != u) {
            return u.getOperNo();
        }
        return null;
    }


    public static Subject getSubject() {
        return SecurityUtils.getSubject();
    }

    public static String getIp() {
        return getSubject().getSession().getHost();
    }
}
